import React from 'react';
import ReactDom from 'react-dom';
import Tost from './tost';
import './style.css';

export default function(opts){
    //创建一个div 并写入body里
    let div=document.createElement("div"),duration=opts.duration || 2000;
    document.body.appendChild(div);
    //将创建的div和组件Tost挂载在组件App.js里面
    let TostInst=ReactDom.render(<Tost></Tost>,div);
    TostInst.setOpts(opts);
    setTimeout(()=>{
        div.querySelector('.Tost').style.animation='hiddenTOst 0.5 forwards';
        setTimeout(()=>{
            document.body.removeChild(div);
        },100);
        
        if(opts.onClose){
            opts.onClose()
        }
      
    },duration)
};